| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
// UNSUPPORTED: c++03, c++11, c++14, c++17 |
| 9 |
|
| 10 |
// <chrono> |
| 11 |
// class weekday; |
| 12 |
|
| 13 |
// constexpr weekday_indexed operator[](unsigned index) const noexcept; |
| 14 |
// constexpr weekday_last operator[](last_spec) const noexcept; |
| 15 |
|
| 16 |
|
| 17 |
#include <chrono> |
| 18 |
#include <type_traits> |
| 19 |
#include <cassert> |
| 20 |
|
| 21 |
#include "test_macros.h" |
| 22 |
#include "../../euclidian.h" |
| 23 |
|
| 24 |
int main(int, char**) |
| 25 |
{ |
| 26 |
using weekday = std::chrono::weekday; |
| 27 |
using weekday_last = std::chrono::weekday_last; |
| 28 |
using weekday_indexed = std::chrono::weekday_indexed; |
| 29 |
|
| 30 |
constexpr weekday Sunday = std::chrono::Sunday; |
| 31 |
|
| 32 |
ASSERT_NOEXCEPT( std::declval<weekday>()[1U]); |
| 33 |
ASSERT_SAME_TYPE(weekday_indexed, decltype(std::declval<weekday>()[1U])); |
| 34 |
|
| 35 |
ASSERT_NOEXCEPT( std::declval<weekday>()[std::chrono::last]); |
| 36 |
ASSERT_SAME_TYPE(weekday_last, decltype(std::declval<weekday>()[std::chrono::last])); |
| 37 |
|
| 38 |
static_assert(Sunday[2].weekday() == Sunday, ""); |
| 39 |
static_assert(Sunday[2].index () == 2, ""); |
| 40 |
|
| 41 |
for (unsigned i = 0; i <= 6; ++i) |
| 42 |
{ |
| 43 |
weekday wd(i); |
| 44 |
weekday_last wdl = wd[std::chrono::last]; |
| 45 |
assert(wdl.weekday() == wd); |
| 46 |
assert(wdl.ok()); |
| 47 |
} |
| 48 |
|
| 49 |
for (unsigned i = 0; i <= 6; ++i) |
| 50 |
for (unsigned j = 1; j <= 5; ++j) |
| 51 |
{ |
| 52 |
weekday wd(i); |
| 53 |
weekday_indexed wdi = wd[j]; |
| 54 |
assert(wdi.weekday() == wd); |
| 55 |
assert(wdi.index() == j); |
| 56 |
assert(wdi.ok()); |
| 57 |
} |
| 58 |
|
| 59 |
return 0; |
| 60 |
} |